part of '../../repository.dart';

const _kGooglePlayTransactionRevocationSourceKey = 'source';
const _kGooglePlayTransactionRevocationReasonKey = 'reason';
const _kGooglePlayTransactionRevocationTimeKey = 'time';

class _GooglePlayTransactionRevocationInfoDto extends Equatable {
  const _GooglePlayTransactionRevocationInfoDto._internal({
    required this.sourceDto,
    required this.reasonDto,
    required this.timeDto,
  });

  final _GooglePlayTransactionRevocationSourceDto sourceDto;
  final _GooglePlayTransactionRevocationReasonDto reasonDto;
  final ApiTimeDto timeDto;

  @override
  List<Object?> get props {
    return [
      sourceDto,
      reasonDto,
      timeDto,
    ];
  }

  factory _GooglePlayTransactionRevocationInfoDto.fromJson(Map<String, dynamic> json) {
    final sourceString = json[_kGooglePlayTransactionRevocationSourceKey] as String;
    final sourceDto = _GooglePlayTransactionRevocationSourceDto.fromString(sourceString);

    final reasonString = json[_kGooglePlayTransactionRevocationReasonKey] as String;
    final reasonDto = _GooglePlayTransactionRevocationReasonDto.fromString(reasonString);

    final timeString = json[_kGooglePlayTransactionRevocationTimeKey] as String;
    final timeDto = ApiTimeDto.fromString(timeString);

    return _GooglePlayTransactionRevocationInfoDto._internal(
      sourceDto: sourceDto,
      reasonDto: reasonDto,
      timeDto: timeDto,
    );
  }

  GooglePlayTransactionRevocationInfo toEntity() {
    return GooglePlayTransactionRevocationInfo(
      source: sourceDto.toEntity(),
      reason: reasonDto.toEntity(),
      time: timeDto.toEntity(),
    );
  }
}
